var PersistantOptions = {
  prefs: Components.classes["@mozilla.org/preferences-service;1"].
         getService(Components.interfaces.nsIPrefBranch).
         QueryInterface(Components.interfaces.nsIPrefBranchInternal),
  
  isBooleanEnabled: function(what, defval) {
    if(this.prefs.getPrefType(what) == this.prefs.PREF_BOOL)
      return this.prefs.getBoolPref(what);
    else {
      this.prefs.setBoolPref(what, defval);
      return true;
    }
  },

  setBoleanEnabled: function(what, enabled) {
    return this.prefs.setBoolPref(what, enabled); 
  },

  get dn()   { return "nepotask.desktopNotif"; },
  get dnp()  { return "nepotask.nepotaskPrompt"; },
  get abt()  { return  "nepotask.addBookmarkTags"; },
  get abtp() { return "nepotask.addBookmarkTagsPromt"; },
  get mf()   { return "nepotask.microformat"; },
  get mfp()  { return "nepotask.microformatPromt"; },

  isDesktopNotifEnabled: function() {
    return this.isBooleanEnabled(this.dn, true);
  },

  setDesktopNotifEnabled: function(enabled) {
    this.setBoleanEnabled(this.dn, enabled);
  },

  isNepotaskPromptEnabled: function() {
    return this.isBooleanEnabled(this.dnp, false);
  },

  setNepotaskPromptEnabled: function(enabled) {
    this.setBoleanEnabled(this.dnp, enabled);
  },

  isAddBookmarkTagsEnabled: function() {
    return this.isBooleanEnabled(this.abt, true);
  },

  setAddBookmarkTagsEnabled: function() {
    this.setBoleanEnabled(this.abt, enabled);
  },

  isAddBookmarkTagsPromptEnabled: function() {
    return this.isBooleanEnabled(this.abtp, false);
  },

  setAddBookmarkTagsPromptEnabled: function() {
    this.setBoleanEnabled(this.abtp, enabled);
  },

  isMicroformatEnabled: function() {
    return this.isBooleanEnabled(this.mf, false);
  },

  setMicroformatEnabled: function() {
    this.setBoleanEnabled(this.mf, enabled);
  },

  isMicroformatPromtEnabled: function() {
    return this.isBooleanEnabled(this.mfp, true);
  },

  setMicroformatPromtEnabled: function() {
    this.setBoleanEnabled(this.mfp, enabled);
  },
}

function onNepotaskOptionsLoad() {
  document.getElementById("checkbox-nepotask-dn").checked = PersistantOptions.isDesktopNotifEnabled();
  document.getElementById("checkbox-nepotask-mf").checked = PersistantOptions.isMicroformatEnabled();
}

function onNepotaskOk() {
  enabled = document.getElementById("checkbox-nepotask-dn").checked;
  PersistantOptions.setDesktopNotifEnabled(enabled);
  enabled = document.getElementById("checkbox-nepotask-mf").checked;
  PersistantOptions.setMicroformatEnabled(enabled);
  window.close();
}